﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace LandandSurvey
{
    public partial class SearchJNPlans : System.Web.UI.Page
    {
        protected void Page_Load( object sender, EventArgs e )
        {

        }

        protected void btnSearch_Click( object sender, EventArgs e )
        {
            gvResults.DataSource = Search();
            gvResults.DataBind();
        }

        private List<PlanItem> Search()
        {
            landsdbEntities container = new landsdbEntities();

            var results = from i in container.PlanItems
                          select i;

            if ( txtAcreage.Text != string.Empty )
            {
                results = from i in results
                          where i.Acreage.Contains( txtAcreage.Text )
                          select i;
            }

            if ( txtDateSigned.Text != string.Empty )
            {
                results = from i in results
                          where i.DateSigned == txtAcreage.Text
                          select i;
            }

            if ( txtLocation.Text != string.Empty )
            {
                results = from i in results
                          where i.Location.Contains( txtLocation.Text )
                          select i;
            }

            if ( txtOwner.Text != string.Empty )
            {
                results = from i in results
                          where i.Owner.Contains( txtOwner.Text )
                          select i;
            }

            if ( txtPlanReference.Text != string.Empty )
            {
                results = from i in results
                          where i.PlanReference == txtPlanReference.Text
                          select i;
            }

            if ( txtSheetNumber.Text != string.Empty )
            {
                results = from i in results
                          where i.SheetNumber.Contains( txtSheetNumber.Text )
                          select i;
            }

            if ( txtSurveyor.Text != string.Empty )
            {
                results = from i in results
                          where i.Surveyor.Contains( txtSurveyor.Text )
                          select i;
            }

            return results.ToList<PlanItem>();
        }
    }
}